<?php
class ManageAction extends Action {
    private $level = null;      //管理员等级模型对象句柄
    public function __construct() {
        $this->level = new LevelModel();
        parent::__construct();
    }

    public function index() {
        parent::page();
        $this->tpl->assign('allManage',$this->model->findAll());
        $this->tpl->display(SMARTY_ADMIN.'manage/show.html');
    }

    public function add() {
        $this->tpl->assign('allLevel',Tool::setObjectArray($this->level->findAll(),'id','level_name'));
        if(isset($_POST['send'])) {
            $this->model->add() ? $this->redirect->succ('?a=manage','管理员添加成功!') : $this->redirect->error('系统出错，管理员添加失败!');
        }
        $this->tpl->display(SMARTY_ADMIN.'manage/add.html');
    }

    public function delete() {
        if(isset($_GET['id'])) {
            $this->model->delete() ? $this->redirect->succ(Tool::getPrevPage(),'管理员删除成功!') : $this->redirect->error('系统出错，管理员删除失败!');
        }
    }

    public function update() {
        if(isset($_GET['id'])) {
            if(isset($_POST['send'])) {
                $this->model->update() ? $this->redirect->succ(Tool::getPrevPage(),'管理员修改成功!') : $this->redirect->error('系统出错，管理员修改失败!');
            }
            $this->tpl->assign('allLevel',Tool::setObjectArray($this->level->findAll(),'id','level_name'));
            $this->tpl->assign('oneManage',$this->model->findOne());
        }
        $this->tpl->display(SMARTY_ADMIN.'manage/update.html');
    }

    public function checkUserName() {
        $this->model->checkUserName();
    }

}
?>